package org.pqw.bookmodel.util;

import java.io.UnsupportedEncodingException;
import java.util.Random;

public class UserCreator {
    private static short[] phoneHead={133,149,153,173,177,180,181,189,199,130,131,132,145,155,156,166,171,175,176,185,186,166,
            134,135,136,137,138,139,147,150,151,152,157,158,159,172,178,182,183,184,187,188,198};
    private static final String CHARS = "qwertyuiopasdfghjklzxcvbnmQEERTYUIOPASDFGHJKLMNBVCXZ1234567890";
    private static final String EMAIL_SYMBOL = "@";
    private static final String SPOT = ".";


    public static String getUsername(){
        String username="";
        for (int i = 0; i < 4; i++) {
            username+=getRandomChar();
        }
        return username;
    }
    public static String getPassword(){

        Random random=new Random();
        int size = random.nextInt(5) + 10;
        char[] password=new char[size];
        for (int i = 0; i < password.length; i++) {
            password[i]=(char)(random.nextInt(93)+33);
        }


        return new String(password);
    }

    public static int getSex(){
        Random random=new Random();
        return random.nextInt(2);
    }

    public static String getPhone(){
        Random random = new Random();
        String head = String.valueOf(phoneHead[random.nextInt(phoneHead.length)]);
        String body="";
        for (int i = 0; i < 8; i++) {
            body += String.valueOf(random.nextInt(10));
        }

        return head+body;
    }



    public static String generateEmail(){
        StringBuilder email = new StringBuilder();
        Random random = new Random();
        int prefix = random.nextInt(10) + 6;
        int suffix = random.nextInt(4) + 5;
        int spotIndex = random.nextInt(suffix - 4) + 2;
        char[] chars = CHARS.toCharArray();
        for (int i = 0; i < prefix; i++) {
            email.append(chars[random.nextInt(chars.length)]);
        }
        email.append(EMAIL_SYMBOL);
        for (int i = 0; i < suffix; i++) {
            if (i == spotIndex){
                email.append(SPOT);
            }
            email.append(chars[random.nextInt(chars.length)]);
        }
        return email.toString();
    }
   /* public static class RandomPwd {
        private static final String lowStr = "abcdefghijklmnopqrstuvwxyz";
        private static final String specialStr = "~!@#$%^&*()_+/-=[]{};:'<>?.";
        private static final String numStr = "0123456789";

        // 随机获取字符串字符
        private static char getRandomChar(String str) {
            SecureRandom random = new SecureRandom();
            return str.charAt(random.nextInt(str.length()));
        }
        // 随机获取小写字符
        private static char getLowChar() {
            return getRandomChar(lowStr);
        }

        // 随机获取大写字符
        private static char getUpperChar() {
            return Character.toUpperCase(getLowChar());
        }

        // 随机获取数字字符
        private static char getNumChar() {
            return getRandomChar(numStr);
        }

        // 随机获取特殊字符
        private static char getSpecialChar() {
            return getRandomChar(specialStr);
        }
    }
*/

    private static char getRandomChar() {
        String str = "";
        int hightPos; //
        int lowPos;
        Random random = new Random();
        hightPos = (176 + Math.abs(random.nextInt(39)));
        lowPos = (161 + Math.abs(random.nextInt(93)));
        byte[] b = new byte[2];
        b[0] = (Integer.valueOf(hightPos)).byteValue();
        b[1] = (Integer.valueOf(lowPos)).byteValue();
        try {
            str = new String(b, "GBK");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            System.out.println("错误");
        }
        return str.charAt(0);
    }


    public static void main(String[] args) {
        Random random = new Random();
        for (int i = 0; i < 10; i++) {
            System.out.println(String.valueOf(random.nextInt(9)+1)+
                    String.valueOf(random.nextInt(9)+1)+
                    String.valueOf(random.nextInt(9)+1)+
                    String.valueOf(random.nextInt(9)+1));
        }
        }

}
